package cs2340.droidceptiontodo;

import android.util.Log;

/**
 * This class holds the information for a to-do item, such
 * as it's name, location, and due date.
 * 
 * @author Roberta
 *
 */
public class ToDoItem {
	private String name;
	private String details;
	private Category category;
	private String dueDate;
	private String dueTime;
//	private DateAndTime dateAndTime;
	private String location;
	private String user;
	private boolean isChecked;
	private String id;
	// TODO: Finalize types for dueDate, dueAt, and location
	
	/**
	 * Constructor defines what the to-do item is
	 * 
	 * @param itemName The to-do item's title or name
	 * @param dueDate The day the to-do item is due (optional)
	 * @param dueTime The time the to-do item is due (optional)
	 * @param details A detailed description about the to-do item (optional)
	 * @param category A general category the to-do item may belong to (optional)
	 * @param location The location of the to-do item (optional)
	 * @param isChecked True if item is marked as complete
	 * @param id Unique ID for database
	 */
	public ToDoItem(String itemName, String user, String details, String category, String dueDate, String dueTime,
			String location, boolean isChecked, String id) {
		this.isChecked = isChecked;
		this.name = itemName;
		this.user = user;
		this.dueDate = dueDate;
		this.dueTime = dueTime; 
		//dateAndTime = new DateAndTime();
		//Log.d("Debug", "DateAndTime object created");
		//Log.d("Debug", "dueDate: " + dueDate);
	//	dateAndTime.setDate(dueDate);
	//	Log.d("Debug", "dueDate set");
	//	dateAndTime.setTime(dueTime);
		Log.d("Debug", "dueTime set");
		this.details = details;
		Category.addCategory(category);
		this.category = Category.getCategory(category);
		this.location = location;
		this.id = id;
		}
	/**
	 * Alternative constructor. Makes all Strings null.
	 * Intended for when you need to initialize a to-do item but
	 * will set it equal to a pre-existing to-do item later
	 * (Used in ToDoListAdapter)
	 */
	public ToDoItem() {
		new ToDoItem("", "", "", "", "", "",
				"", false, "");
	}
	/**
	 * Alternate constructor, called when loading a user's to-do items ??????????????????
	 * ^not sure if that is accurate, just an assumption --Roberta
	 * 
	 * dunno how to deal with this? >> SHEENA O_O
	 * 
	 * @param itemComponents A string array containing all necessary parameters to
	 * create a to-do item
	 */
	/**public ToDoItem(String[] itemComponents) {
		this(itemComponents[0],
				itemComponents[1],
				itemComponents[2],
				itemComponents[3],
				itemComponents[4],
				itemComponents[5],;
	}
	*/
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDetails() {
		return details;
	}

	public void setDetails(String details) {
		this.details = details;
	}

	public Category getCategory() {
		return category;
	}

	public void setCategory(String category) {
		Category.addCategory(category);
		this.category = Category.getCategory(category);
	}

	public String getDueDate() {
		return dueDate;
	}

	public void setDueDate(String dueDate) {
		this.dueDate = dueDate;
	}

	public String getDueTime() {
		return dueTime;
	}

	public void setDueTime(String dueTime) {
		this.dueTime = dueTime;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public boolean isChecked() {
		return isChecked;
	}

	public void setChecked(boolean isChecked) {
		this.isChecked = isChecked;
	}
	
	/**
	 * This method is used to convert the ToDoItem's data into a single string so it can be 
	 * inserted into a file for saving.
	 * 
	 */
	
	@Override
	public String toString()
	{
		String categoryStr = category.getName();
		
		// Make sure none of the values == "". Change to "null" instead
		dueDate = dueDate.equals("")? "null" : dueDate;
		dueTime = dueTime.equals("")? "null" : dueTime;
		details = details.equals("")? "null" : details;
		categoryStr = categoryStr.equals("")? "null" : categoryStr;
		location = location.equals("")? "null" : location;
		
		return ( name +":"+ dueDate+ ":"+ dueTime+":"+ details +":"+ categoryStr +":" + location);
	}
	public String getUser() {
		return user;
	}
	
	public String getID() {
		return id;
	}
	/**
	 * 
	 * @return True if a due date has been set
	 */
	public boolean hasDueDate() {
		// TODO Auto-generated method stub
		return dueDate.equals("")? false : true;
	}
	/**
	 * @return True if a due time has been set
	 */
	public boolean hasDueTime() {
		return dueTime.equals("")? false : true;
	}
		
}
